#!/bin/bash
VERSION=`date '+%Y%m%d'`
ARCH=i486
PKG=odcgi
USR="--owner 1000 --group 1000 --same-permissions "
EXCLUDE=" --exclude '*~' --exclude .svn --exclude usr/local/opendomo/services/config/user"

echo "Web interface" > pkg/$PKG.desc
echo "This package allow the access to all the resources in the network" >> pkg/$PKG.desc
cp pkg/*.desc ./var/pkg


make clean && make || exit 1
rm -fr pkg/o*.tar.gz

chmod +x var/pkg/*.sh
tar cvfz ./pkg/$PKG-$VERSION.od.$ARCH.tar.gz var etc usr $USR $EXCLUDE

if ! test -f jquery/var/www/scripts/jquery.min.js; then
	echo "Downloading jQuery"
	wget -q http://code.jquery.com/jquery-1.6.1.min.js -O jquery/var/www/scripts/jquery.min.js
fi
cd jquery
tar cfz ./../pkg/${PKG}_jquery-$VERSION.noarch.tar.gz var $USR $EXCLUDE
cd ..
echo "jQuery library" > pkg/${PKG}_jquery.desc

if ! test -f flot/var/www/scripts/jquery.flot.js; then
	wget http://flot.googlecode.com/files/flot-0.7.tar.gz -O flot.tar.gz
	tar -zxvf flot.tar.gz
	cp flot/*.js flot/var/www/scripts 
	rm flot/var/www/scripts/jquery.js flot/var/www/scripts/jquery.min.js
fi

cd flot
tar cfz ./../pkg/${PKG}_flot-$VERSION.noarch.tar.gz var usr $USR $EXCLUDE
cd ..
echo "Flot library" > pkg/${PKG}_flot.desc


cd datepicker
if ! test -f date-picker-v5/var/www/scripts/datepicker/js/datepicker.packed.js; then
	tar xvfz date-picker.tar.gz # could not download it from the website, it always fails
	cp -fR date-picker-v5/* var/www/scripts/datepicker/
fi

tar cfz ./../pkg/${PKG}_datepicker-$VERSION.noarch.tar.gz var $USR $EXCLUDE
cd ..
echo "Datepicker library" > pkg/${PKG}_datepicker.desc

cd 
